import React, {
    Component,
} from 'react';
import {
    View,
    TouchableOpacity,
    StyleSheet,
} from 'react-native';

/*传入参数
    activeOpacity 点击透明度默认0.8
    style按钮样式默认无样式
    onPress点击事件回调函数*/
export default class NewButton extends Component {
    constructor(props) {
        super(props);
        this.state = {
            disabled:false,//防止多次点击
        }
    }
    render(){
        return (
            <TouchableOpacity 
                activeOpacity={this.props.activeOpacity?this.props.activeOpacity:0.8}
                style={this.props.style?this.props.style:styles.button}
                onPress={this.click.bind(this)}
                disabled={this.state.disabled}>
                {this.props.children}
            </TouchableOpacity>
    
        )
    }
    click=()=>{
        this.setState({
            disabled:true,    
        })
        try{
            if(this.props.onPress){
                this.props.onPress();
                setTimeout(()=>{
                    this.setState({
                        disabled:false,    
                    })
                },300)
            }
            else{
                return '';
            }
        }
        catch(e){

        }
        
    } 
    
}

const styles = StyleSheet.create({
    button:{
        
    },
})